﻿var xmlHttp;

function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        }
    }
}

function modifySubmit(){
	var introContent = editor.getText();
	createXMLHttpRequest();
	var url = "modify";
	xmlHttp.onreadystatechange = handleModifyStateChanged;
    xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader('Connection', 'close');
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	var parameter = "introAddr=" + encodeURI(global_introAddr) + "&introContent=" + introContent.replace(/&/g,"%26");
	alert(parameter);
    xmlHttp.send(parameter);
}
	
function handleModifyStateChanged(){
	if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            modifyResult();
        }else{
        	alert("status:"+xmlHttp.status);
        }
    }
}

function modifyResult(){
	var xmlDoc = xmlHttp.responseXML.documentElement;
	var result = xmlDoc.getElementsByTagName("result").item(0).firstChild.nodeValue;
	
	if(result == "success"){		
		EDBox.style.display="none";
		RPBox.getElementsByTagName("div")[global_n].innerHTML=editor.getText();
		RPBox.style.display="block";
	}else if(result == "failure"){
		alert("保存失败,请重试.");
	}else{
		alert("Unknown return value!");
	}
}
